-- ship_attack
-- create by cheny3
-- 幽灵船主动攻击

return {
    -- 判断
    canTrigger = function(args)
        if not ME.user.ship then
            return false;
        end

        local dungeonId = DungeonM.getDungeonId();
        local layer = DungeonM.currentLayer();
        if DungeonBossM.isBossLayer(dungeonId, layer) then
            -- BOSS层不允许操作
            return false;
        end

        -- 判断是否有存活的怪物
        local aliveMonsters = AutoFightM.getData()["aliveMonsters"];
        if aliveMonsters and #aliveMonsters > 0 then
            return true;
        end
        return false;
    end,

    -- 触发
    trigger = function(args)
        local aliveMonsters = AutoFightM.getData()["aliveMonsters"];
        if not aliveMonsters or #aliveMonsters <= 0 then
            return false;
        end

        -- 主动技
        local skillId = GhostShipM.getInitiativeSkill();
        -- 尝试攻击
        return DungeonActionM.go("use_ship_skill", -1, skillId);
    end,
};
